package com.nanbei.orderService.service.impl;

import com.nanbei.commonUntil.vo.orderVo.CourseWebVoOrder;
import com.nanbei.commonUntil.vo.orderVo.UcenterMemberOrder;
import com.nanbei.orderService.client.OrderCenterClient;
import com.nanbei.orderService.client.OrderCourseClient;
import com.nanbei.orderService.controller.OrderController;
import com.nanbei.orderService.entity.Order;
import com.nanbei.orderService.mapper.OrderMapper;
import com.nanbei.orderService.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nanbei.orderService.utils.OrderNoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2022-02-14
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    private OrderCenterClient orderCenterClient;

    @Autowired
    private OrderCourseClient orderCourseClient;

    @Override
    public String getOrderId(String courseId, String memberId) {

        //获取课程信息
        CourseWebVoOrder courseWebVoOrder = orderCourseClient.orderFindCourseInfo(courseId);

        //获取用户信息
        UcenterMemberOrder ucenterMemberOrder = orderCenterClient.orderUserInfo(memberId);

        Order order = new Order();

        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId);
        order.setCourseTitle(courseWebVoOrder.getTitle());
        order.setCourseCover(courseWebVoOrder.getCover());
        order.setTeacherName(courseWebVoOrder.getTeacherName());
        order.setTotalFee(courseWebVoOrder.getPrice());
        order.setMemberId(memberId);
        order.setMobile(ucenterMemberOrder.getMobile());
        order.setNickname(ucenterMemberOrder.getNickname());
        order.setStatus(0);   //支付状态 0：未支付 1：已支付
        order.setPayType(1);  //支付类型 1：微信支付（默认）
        this.baseMapper.insert(order);

        System.out.println(order.getOrderNo());
        return order.getOrderNo();
    }
}
